package net.wwang.blog.controller.admin;

import net.wwang.blog.commons.global.ResponseResult;
import net.wwang.blog.pojo.Category;
import net.wwang.blog.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author WangWei
 * @date 2020/8/14
 */
@RestController
@RequestMapping(value = "/admin/category")
public class CategoryAdminApi {
    @Autowired
    private CategoryService categoryService;

    /**
     * 添加分类
     * @param category
     * @return
     */
    @PreAuthorize("@permission.isRoleAdmin()")
    @PostMapping
    public ResponseResult addCategory(@RequestBody Category category){
        return categoryService.addCategory(category);
    }

    /**
     * 删除分类
     * @param categoryId
     * @return
     */
    @PreAuthorize("@permission.isRoleAdmin()")
    @DeleteMapping(value = "/{categoryId}")
    public ResponseResult delCategory(@PathVariable("categoryId") String categoryId){
        return categoryService.deleteCategory(categoryId);
    }

    /**
     * 修改分类
     * @param categoryId
     * @param category
     * @return
     */
    @PreAuthorize("@permission.isRoleAdmin()")
    @PutMapping(value = "/{categoryId}")
    public ResponseResult updateCategory(@PathVariable("categoryId") String categoryId,@RequestBody Category category){
        return categoryService.updateCategory(categoryId,category);
    }

    /**
     * 根据ID查询分类
     * @param categoryId
     * @return
     */
    @PreAuthorize("@permission.isRoleAdmin()")
    @GetMapping(value = "/{categoryId}")
    public ResponseResult getCategory(@PathVariable("categoryId") String categoryId){
        return categoryService.getCategoryDetail(categoryId);
    }

    /**
     * 查询分类列表
     * @param page
     * @param size
     * @return
     */
    @GetMapping(value = "/list")
    public ResponseResult getCategoryList(@RequestParam("page")int page,@RequestParam("size")int size){
        return null;
    }
}
